/*
*	Copyright (C) 2014  Julio Montes, Mario Carrillo
*	
*	Julio Montes e-mail: imc.coder@gmail.com 
*
*	Mario Carrillo e-mail: mario_90ago@live.com.mx
*
*	BSD 3-Clause License
*/

#include "alliance/include/viewerdialog.h"

#include "alliance/include/toolpanel.h"
#include "alliance/include/processmgr.h"
#include "alliance/include/projectmgr.h"
#include "alliance/include/project.h"

namespace alliance
{
    ViewerDialog::ViewerDialog( wxWindow *parent, const wxString &title, const wxString &viewerFile )
        : wxDialog( parent, wxID_ANY, title, wxDefaultPosition, wxSize( 600, 620 ), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER  )
        , m_toolPanel( NULL )
    {
        m_toolPanel = new ToolPanel( this, wxID_ANY );
        if( m_toolPanel->LoadFile( viewerFile ) )
        {
            wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
            sizer->Add( m_toolPanel, 1, wxEXPAND | wxALL, 10 );

            wxBoxSizer *sizerButtons = new wxBoxSizer( wxHORIZONTAL );
            sizerButtons->Add( new wxButton( this, wxID_OK ) );
            sizerButtons->AddSpacer( 10 );
            sizerButtons->Add( new wxButton( this, wxID_CANCEL ) );
            sizer->Add( sizerButtons, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 10 );

            SetSizer( sizer );

            Connect( wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( ViewerDialog::OnOk ), NULL, this );
        }
    }

    ViewerDialog::~ViewerDialog()
    {

    }

    void ViewerDialog::OnOk( wxCommandEvent &evt )
    {
        if( m_toolPanel && m_toolPanel->IsOk() )
        {
            EndModal( evt.GetId() );
            const Tool &viewer = m_toolPanel->GetTool();
            ProcessManager::Get()->LaunchViewer( ProjectManager::Get()->GetActiveProject(), viewer );
        }
    }
}
